package com.example.controller;

import com.example.annotation.Log;
import com.example.config.SaTokenConfiguration;
import com.example.entity.SysOperLog;
import com.example.service.SysOperLogService;
import com.example.common.api.ApiResult;
import com.example.enums.BusinessType;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * 操作日志记录
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperLogController {
    @Autowired
    private SysOperLogService operLogService;

    @Autowired
    private SaTokenConfiguration saTokenConfiguration;

    @SaCheckPermission("monitor:operlog:list")
    @GetMapping("/list")
    public ApiResult<List<SysOperLog>> list(SysOperLog operLog) {
        // 创建分页对象，默认查询第一页，每页10条
        Page<SysOperLog> page = new Page<>(1, 10);
        Page<SysOperLog> result = operLogService.selectOperLogPage(page, operLog);
        return ApiResult.success(result.getRecords());
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @SaCheckPermission("monitor:operlog:remove")
    @DeleteMapping("/{operIds}")
    public ApiResult<Integer> remove(@PathVariable Long[] operIds) {
        return ApiResult.success(operLogService.deleteOperLogByIds(java.util.Arrays.asList(operIds)));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @SaCheckPermission("monitor:operlog:clean")
    @DeleteMapping("/clean")
    public ApiResult<Void> clean() {
        operLogService.cleanOperLog();
        return ApiResult.success();
    }
} 